//
//  WCBuildTargetsGroup.m
//  WabbitCode
//
//  Created by William Towe on 1/22/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "WCBuildTargetsGroup.h"
#import "WCBuildTarget.h"
#import "NSArray+WCExtensions.h"
#import "WCProject.h"


@implementation WCBuildTargetsGroup
#pragma mark *** Subclass Overrides ***
- (NSString *)name {
	return NSLocalizedString(@"Build Targets",@"Build Targets");
}

- (NSImage *)icon {
	return [NSImage imageNamed:@"BuildTarget16x16"];
}

- (BOOL)canRenameNode {
	return NO;
}

- (BOOL)canDeleteNode {
	return NO;
}

- (BOOL)canGetInfo {
	return NO;
}

- (NSString *)nodeToolTip {
	return [NSString stringWithFormat:NSLocalizedString(@"Total Build Targets: %u\nActive Build Target: %@",@"nodeToolTip for WCBuildTargetsGroup"), [self numberOfBuildTargets], [[self activeBuildTarget] name]];
}

- (BOOL)isRootLevelGroup {
	return YES;
}

#pragma mark *** Public Methods ***
#pragma mark Accessors
@synthesize project=_project;

- (void)setProject:(WCProject *)value {
	if (_project == value)
		return;
	
	_project = value;
}

@dynamic activeBuildTarget;
- (WCBuildTarget *)activeBuildTarget {
	for (WCBuildTarget *target in [self childNodes])
		if ([target isTargetActive])
			return target;
	
	if ([[self childNodes] count]) {
		[self setActiveBuildTarget:[[self childNodes] firstObject]];
		return [self activeBuildTarget];
	}
	return nil;
}

- (void)setActiveBuildTarget:(WCBuildTarget *)value {
	for (WCBuildTarget *target in [self childNodes])
		[target setIsTargetActive:NO];
	
	[value setIsTargetActive:YES];
}

@dynamic numberOfBuildTargets;
- (NSUInteger)numberOfBuildTargets {
	return [[self childNodes] count];
}
#pragma mark Creation
+ (id)buildTargetsGroup; {
	return [super treeNodeWithNodeName:nil];
}
@end
